import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * 导航传递参数到父页面
 */
class MyApp15 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "FirstPage title",
      home: FirstPage(),
    );
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("FirstPage"),
      ),
      body: Center(
        child: RouteButton(),
      ),
    );
  }
}

class RouteButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      onPressed: () {
        navigator2Second(context);
      },
      child: Text("RouteButton"),
      color: Colors.deepPurpleAccent,
    );
  }

  navigator2Second(BuildContext context) async {
    final result = await Navigator.push(
        context, MaterialPageRoute(builder: (context) => SecondPage()));
    Scaffold.of(context).showSnackBar(SnackBar(content: Text("$result")));
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("SecondPage"),
      ),
      body: Center(
        child: ListView(
          children: [
            RaisedButton(
              onPressed: () {
                Navigator.pop(context,"9527");
              },
              color: Colors.green,
              child: Text("9527"),
            ),
            RaisedButton(
              onPressed: () {
                Navigator.pop(context,"9528");
              },
              color: Colors.deepPurple,
              child: Text("9528"),
            ),
            RaisedButton(
              onPressed: () {
                Navigator.pop(context,"9529");
              },
              color: Colors.purple,
              child: Text("9529"),
            )
          ],
        ),
      ),
    );
  }
}
